const { Paragraph, TextRun, Tab, TabStopType, TabStopPosition } = require("docx");
const { getIndentValue } = require("../common/utils");

function generateSignatureDateField(field, baseIndent = 0) {
    const { 
        signatureLabel = '研究者签字:', 
        signatureLineLength = 5, // cm
        dateLabel = '日期: 202',
        alignment = 'indent-0',
        isBold = false
    } = field.value || {};

    const finalIndent = getIndentValue(alignment, baseIndent);

    return [
        new Paragraph({
            indent: { left: finalIndent },
            spacing: { line: 360 },
            children: [
                new TextRun({
                    text: `${signatureLabel} ` + '_'.repeat(Math.round(signatureLineLength * 4)), // Adjust multiplier for visual length
                    size: 21, // 5号字体
                    font: "SimSun", // 宋体
                    bold: isBold
                }),
                new TextRun({
                    text: `\t${dateLabel}|___|年|___|月|___|日`,
                    size: 21, // 5号字体
                    font: "SimSun", // 宋体
                    bold: isBold
                }),
            ],
            tabStops: [
                {
                    type: TabStopType.RIGHT,
                    position: TabStopPosition.MAX,
                },
            ],
        }),
    ];
}

module.exports = {
  generateSignatureDateField,
}; 